package com.gtw.modules.sys.controller;

import com.gtw.common.annotation.SysLog;
import com.gtw.common.utils.PageUtils;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.modules.entity.TbDividendRule;
import com.gtw.modules.entity.TbDividends;
import com.gtw.modules.sys.service.SysDividendRuleservice;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by wuye on 2018/5/22.
 */
@RestController
@RequestMapping("/sys/dividendrule")
public class SysDividendRuleController {

    @Autowired
    private SysDividendRuleservice dividendRuleservice;

    /**
     * 查询所有分红规则
     * @return
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:dividendrule:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<TbDividendRule> dividendsList = dividendRuleservice.queryList(query);
        int total = dividendRuleservice.queryTotal(query);

        PageUtils pageUtil = new PageUtils(dividendsList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:dividendrule:info")
    public R info(@PathVariable("id") Integer id){
        TbDividendRule dividendRule = dividendRuleservice.queryObject(id);

        return R.ok().put("dividendRule", dividendRule);
    }

    /**
     * 保存
     */
    @SysLog("添加分红规则")
    @RequestMapping("/save")
    @RequiresPermissions("sys:dividendrule:save")
    public R save(@RequestBody TbDividendRule dividendRule){
        dividendRule.setCreatetime(new Date());
        dividendRuleservice.save(dividendRule);

        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改分红规则")
    @RequestMapping("/update")
    @RequiresPermissions("sys:dividendrule:update")
    public R update(@RequestBody TbDividendRule dividendRule){
        dividendRuleservice.update(dividendRule);

        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除分红规则")
    @RequestMapping("/delete")
    @RequiresPermissions("sys:dividendrule:delete")
    public R delete(@RequestBody Integer[] ids){
        dividendRuleservice.deleteBatch(ids);

        return R.ok();
    }
}
